<template>
  <div class="login-panel">
    <h1 class="title">V3-TS后台管理系统</h1>
    <el-tabs type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span>
            <el-icon><UserFilled /></el-icon> 账号登录
          </span>
        </template>
        <!-- 内容 -->
        <LoginAccount ref="accountRef"></LoginAccount>
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span>
            <el-icon><Iphone /></el-icon> 手机登录
          </span>
        </template>
        <!-- 内容 -->
        <LoginPhone ref="phoneRef" />
      </el-tab-pane>
    </el-tabs>
    <div class="panel-contr">
      <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
      <el-link>忘记密码</el-link>
    </div>
    <el-button type="primary" class="login-btn" @click="handleLogin"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { Iphone, UserFilled } from '@element-plus/icons-vue';

import LoginAccount from './login-account.vue';
import LoginPhone from './login-phone.vue';

const isKeepPassword = ref(true);

// temp
interface loginAccountType {
  accountLoginAction: (isKeepPassword: boolean) => void;
}

const accountRef = ref<InstanceType<typeof LoginAccount> & loginAccountType>();
const phoneRef = ref();

const currentTab = ref('account');

const handleLogin = () => {
  if (currentTab.value == 'account') {
    accountRef.value?.accountLoginAction(isKeepPassword.value);
  } else {
    // currentTab.value = 'phone';
    console.log('phone登录');
  }
};
</script>

<style lang="less" scoped>
.login-panel {
  width: 380px;
  .title {
    text-align: center;
  }
  .panel-contr {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }
  .login-btn {
    width: 100%;
  }
}
</style>
